/*
 * TOP SECRET Copyright 2006-2015 Transsion.com All right reserved. This software is the confidential and proprietary
 * information of Transsion.com ("Confidential Information"). You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement you entered into with Transsion.com.
 */
package com.yunji.framework_template.biz.crawler.pk;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yunji.framework_template.biz.crawler.ContentImageHandler;
import com.yunji.framework_template.biz.crawler.NewsCrawler;
import com.yunji.framework_template.biz.crawler.SourceType;
import com.yunji.framework_template.common.enumeration.CountryCode;
import com.yunji.framework_template.common.enumeration.NewsType;
import com.yunji.framework_template.common.util.NumberUtil;

/**
 * ClassName:NationNewsCrawler <br/>
 * Date: 2018年12月18日 下午3:31:24 <br/>
 * 
 * @author fenglibin1982@163.com
 * @Blog http://blog.csdn.net/fenglibing
 * @version
 * @see
 */
@Service
public class GeoNewsCrawler extends NewsCrawler {

    @Resource
    private GeoNewsImageHandler geoNewsImageHandler;

    @Override
    public boolean isOkUrl(String url) {
        // 通过判断url的path中是否包括年月来判断其是否为新闻详情页
        URI uri;
        try {
            if (url == null || url.trim().length() == 0) {
                return false;
            }
            if (url.startsWith("mailto") || url.toLowerCase().startsWith("javascript")) {
                return false;
            }
            uri = new URI(url);
            String host = uri.getHost();
            if (host.indexOf("geo.tv") < 0) {
                return false;
            }
            String path = uri.getPath();
            String[] pathArr = path.split("/");
            if (pathArr.length == 3 && NumberUtil.isNumber(pathArr[2].split("-")[0])) {
                return true;
            }
        } catch (URISyntaxException e) {
        }
        return false;
    }

    @Override
    public ContentImageHandler getContentImageHandler() {
        return geoNewsImageHandler;
    }

    @Override
    public List<SourceType> getSourceTypeList() {
        List<SourceType> sourceTypeList = new ArrayList<SourceType>();
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/").newsType(NewsType.HOT).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/latest-news").newsType(NewsType.IMAGE).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/pakistan").newsType(NewsType.SPORT).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/world").newsType(NewsType.LIFESTYLE).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/sports").newsType(NewsType.FUN).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/entertainment").newsType(NewsType.HOUSE).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/business").newsType(NewsType.ASKANDANSWER).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/health").newsType(NewsType.HEALTH).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/amazing").newsType(NewsType.MILITARY).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/sci-tech").newsType(NewsType.CAR).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/category/life-style").newsType(NewsType.TECH).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/tv-shows").newsType(NewsType.FINANCE).build());
        sourceTypeList.add(SourceType.builder().url("https://www.geo.tv/videos").newsType(NewsType.NEWS).build());
        
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/").newsType(NewsType.HOT).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/latest-news").newsType(NewsType.EDUCATION).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/pakistan").newsType(NewsType.VIDEO).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/world").newsType(NewsType.IMAGE).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/sports").newsType(NewsType.SPORT).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/entertainment").newsType(NewsType.LIFESTYLE).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/business").newsType(NewsType.FUN).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/health").newsType(NewsType.HOUSE).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/amazing").newsType(NewsType.ASKANDANSWER).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/category/blog").newsType(NewsType.HEALTH).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/tv-shows").newsType(NewsType.MILITARY).build());
        sourceTypeList.add(SourceType.builder().url("https://urdu.geo.tv/videos").newsType(NewsType.CAR).build());

        return sourceTypeList;
    }

    @Override
    public Set<String> getCountryCodeSet() {
        Set<String> countryCodeSet = new HashSet<String>();
        countryCodeSet.add(CountryCode.PK.name());
        return countryCodeSet;
    }
}
